<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <canvas id="ctx" width="1000" height="1000" style="background-color: #eee;"></canvas>
</body>
</html>


<script>

const canvas = document.querySelector('#ctx')
const ctx = canvas.getContext('2d')
let offset = 0

function draw(){
  ctx.clearRect(0, 0, canvas.width, canvas.height)
  ctx.setLineDash([4, 2]);
  ctx.lineDashOffset = -offset
  ctx.strokeRect(100,100, 500, 500);
}

setInterval(() => {
  offset++;
  if (offset > 16) {
    offset = 0;
  }
  draw(ctx)
}, 33);

</script>